package com.qinggeng.project.api.controller;

import com.qinggeng.framework.web.domain.AjaxResult;
import com.qinggeng.project.api.security.annotation.LoginRequired;
import com.qinggeng.project.api.security.utils.ApiUtils;
import com.qinggeng.project.system.domain.Member;
import com.qinggeng.project.system.dto.MemberDTO;
import com.qinggeng.project.system.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Calendar;

@RestController
@RequestMapping("${apiPath}/test")
@CrossOrigin
public class ApiMemberController {
    @Autowired
    private MemberService memberService;

    //test 获取会员信息
    @GetMapping("")
    //@LoginRequired
    public AjaxResult getMember(){
        //Long userId= ApiUtils.getUserId();
        Member member=memberService.getMember(18L,0);
        if (null==member){
            return AjaxResult.success();
        }
        return AjaxResult.success(member);
    }
    //test 获取 判断是不是会员
    @GetMapping("/isMember")
    //@LoginRequired
    public AjaxResult isMember(){
        //Long userId= ApiUtils.getUserId();
        Integer code=memberService.isMember(18L,0);
        return AjaxResult.success(code);
    }

    //test 获取 判断是不是会员
    @GetMapping("/insert")
    //@LoginRequired
    public AjaxResult insert(){
        //Long userId= ApiUtils.getUserId();
        MemberDTO memberDTO=new MemberDTO();
        memberDTO.setUserId(18L);
        memberDTO.setPhonenumber("17712291310");
        Calendar calendar = Calendar.getInstance();// 获取当前日期
        calendar.add(Calendar.MONTH, 1);
        memberDTO.setEndTime(calendar.getTime());
        boolean bl=memberService.insertMember(memberDTO);
        return AjaxResult.success(bl);
    }




}
